package com.example.agriculyural.State;

import com.example.agriculyural.FactoryMethod.AgriculturalMachine;
import com.example.agriculyural.State.MachineState;
import com.example.agriculyural.State.ReadyState;

// 状态上下文
public class MachineStateContext {
    private MachineState currentState;
    private AgriculturalMachine machine;

    public MachineStateContext(AgriculturalMachine machine) {
        this.machine = machine;
        this.currentState = new ReadyState();
    }

    public void setState(MachineState state) {
        this.currentState = state;
        System.out.println(machine.getMachineType() + " " + machine.getId() + " 状态切换到: " + state.getStateName());
    }

    public void executeState() {
        currentState.handle(machine);
    }

    public String getCurrentStateName() {
        return currentState.getStateName();
    }
}